package top.qingyunge.autumn.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.qingyunge.autumn.annotation.DatabaseConnect;
import top.qingyunge.autumn.annotation.IgnoreToken;
import top.qingyunge.autumn.dao.BlogArticleDAO;
import top.qingyunge.autumn.pojo.BlogArticle;
import top.qingyunge.autumn.service.implement.BlogArticleServiceImpl;
import top.qingyunge.autumn.service.implement.SentenceServiceImpl;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/test")
public class TestController {
    @Resource
    public SentenceServiceImpl  sentenceService;
    @Resource
    public BlogArticleServiceImpl blogArticleService;
    @Resource
    public BlogArticleDAO blogArticleDAO;

    @GetMapping(value = "/test")
    @DatabaseConnect("elegance")
    public String test(){
        return sentenceService.count() + "";
    }

    @GetMapping(value = "/test-blog")
    @DatabaseConnect("blog")
    @IgnoreToken
    public List<BlogArticle> blog(){
        QueryWrapper<BlogArticle> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("id","title");
        Page<BlogArticle> page = new Page<>(1,10);
        List<BlogArticle> blogArticleIPage = blogArticleDAO.selectList(page,queryWrapper);

        return blogArticleIPage;
    }
    @GetMapping(value = "/test-exception")
    @DatabaseConnect("elegance")
    public Integer testException(){
        return 1 / 0;
    }
}